import { ExtIdTuple } from "~/db.pg";
import { ExtIntro } from "~/extend";

import { ExtOwner } from "@/stream-user/core.define";
import { Book, BookContactMap, BookMap } from "@/pond-book/schema.book";

import { TonOrder } from "@/river-ton/schema.order";
import { TonSku } from "@/river-ton/schema.sku";
import { Voucher } from "@/river-voucher/schema.voucher";

import { MarketOrder } from "@/river-market/schema.order";
import { GemSku } from "@/river-market/schema.gem";
import { AppDueSku } from "@/river-market/schema.due";

/** 联系人分组 */
export type ContactGroup = ExtIdTuple &
  ExtOwner &
  ExtIntro & {
    joinContactList?: Contact[];
  };

/** 联系人 */
export type Contact = ExtIdTuple &
  ExtOwner &
  ExtIntro &
  joinContactRelatived & {
    refContactGroupId: ContactGroup["id"];
    justContactGroup?: ContactGroup;
  };

/** 其中包含的结构体，都携带了refContactId */
type joinContactRelatived = {
  // 账簿记录
  joinBookList?: Book[];
  joinBookMapList?: BookMap[];
  joinBookContactMapList?: BookContactMap[];

  /** 用户购买钻石 */
  joinMarketOrderList?: MarketOrder[];
  joinGemSkuList?: GemSku[];
  joinAppDueSkuList?: AppDueSku[];

  // 凭证
  joinVoucherList?: Voucher[];

  // Ton
  joinTonOrderList?: TonOrder[];
  joinTonSkuList?: TonSku[];
};
